import xadmin
from .models import *
import datetime


# class AppDepartmentAdmin(object):
#     list_display=['id','name','code']
#     search_fields=['name']
#     list_filter=['name']
#     list_editable = ['name']
#     model_icon = 'glyphicon glyphicon-play-circle'
#
# xadmin.site.register(AppDepartment, AppDepartmentAdmin)

class ProjectProductAdmin(object):
    list_display=['product_name', 'product_department', 'product_level', 'product_memo']
    search_fields=['product_name', 'product_department',]
    list_filter=['product_name', 'product_department',]
    list_editable = ['product_name', 'product_department', 'product_level', 'product_memo']
    list_exclude = ['product_update_time']
    ordering = ['-product_update_time']
    model_icon = 'fa fa-book'

    def save_models(self):
        obj = self.new_obj
        if self.org_obj is None:
            obj.save()
            self.log('create',self.change_message(),obj)
        else:
            obj.product_update_time = datetime.datetime.now()
            obj.save()
            self.log('change',self.change_message(),obj)

xadmin.site.register(ProjectProduct, ProjectProductAdmin)